package com.bruce.mqConsumer.service;

import com.bruce.mqConsumer.entity.Order;
import com.rabbitmq.client.Channel;
import org.springframework.amqp.rabbit.annotation.*;
import org.springframework.messaging.handler.annotation.Headers;
import org.springframework.messaging.handler.annotation.Payload;
import org.springframework.stereotype.Component;

import java.util.Map;

/**
 * Created by bruce on 19/1/8 -- 15:57
 */
@Component
public class OrderReceiver {

    @RabbitListener(
            bindings = @QueueBinding(value = @Queue(value = "order-queue"),
                    exchange = @Exchange(name = "order-exchange"),
                    key = "order.hello")
    )
    @RabbitHandler
    public void onOrderMessage(
            @Payload Order order,
            @Headers Map<String, Object> headers,
            Channel channel) throws Exception {
//消费者操作
        System.out.println("订单id》》" + order);
    }
}
